<!doctype html>
<html>
    <head>
        <!-- meta -->
        <!-- meta -->
        <title>Events</title>
        <!-- css -->
        <link href="../styles/examples.css" rel="stylesheet"/>
        <link href="../../source/styles/nova.common.css" rel="stylesheet"/>
        <link href="../../source/styles/nova.css" rel="stylesheet"/>
        <!-- css -->
        <!-- script -->
        <script src="../js/jquery.js"></script>
        <script src="../../source/js/nova.core.js"></script>
        <script src="../../source/js/nova.fx.js"></script>
        <script src="../../source/js/nova.draganddrop.js"></script>
        <script src="../../source/js/nova.treeview.js"></script>
        <script src="../js/nova.console.js"></script>
        <!-- script -->
    </head>
    <body>
        <!-- nav -->
        <!-- nav -->
        <!-- description -->
        <!-- description -->
        <div id="example" class="n-content">
            <div id="treeview"></div>

            <script>
                $(document).ready(function() {
                    var treeview;

                    function onSelect(e) {
                        novaConsole.log("Selected: " + treeview.text(e.node));
                    }

                    function onError(e) {
                        novaConsole.error("Loading failed with " + e.xhr.statusText + " " + e.xhr.status);
                    }

                    function onCollapse(e) {
                        novaConsole.log("Collapsing " + treeview.text(e.node));
                    }

                    function onExpand(e) {
                        novaConsole.log("Expanding " + treeview.text(e.node));
                    }

                    function onDragStart(e) {
                        novaConsole.log("Started dragging " + treeview.text(e.sourceNode));
                    }

                    function onDrag(e) {
                        // omitted event logging in order to prevent console flood
                        // novaConsole.log("Started dragging " + treeview.text(e.sourceNode));
                    }

                    function onDrop(e) {
                        novaConsole.log(
                        "Dropped " + treeview.text(e.sourceNode) +
                        " (" + (e.valid ? "valid" : "invalid") + ")"
                        );
                    }

                    function onDragEnd(e) {
                        novaConsole.log("Finished dragging " + treeview.text(e.sourceNode));
                    }

                    treeview = $("#treeview").novaTreeView({
                        dataSource: [
                            { text: "Item 1", expanded: true, items: [
                                { text: "Item 1.1" },
                                { text: "Item 1.2" },
                                { text: "Item 1.3" }
                            ] },
                            { text: "Item 2", items: [
                                { text: "Item 2.1" },
                                { text: "Item 2.2" },
                                { text: "Item 2.3" }
                            ] },
                            { text: "Item 3" }
                        ],
                        select: onSelect,
                        error: onError,
                        collapse: onCollapse,
                        expand: onExpand,
                        dragAndDrop: true,
                        /* drag & drop events */
                        dragstart: onDragStart,
                        drag: onDrag,
                        drop: onDrop,
                        dragend: onDragEnd
                    }).data("novaTreeView");
                });
            </script>
        </div>
        <div class="console"></div>
        <!-- tools -->
        <!-- tools -->
    </body>
</html>

